import modelExtend from 'dva-model-extend'
import * as testResultService from '../services/testResult'
import { pageModel } from './common'

const { queryspecific } = testResultService
;
export default modelExtend(pageModel, {
  namespace: 'testResults',

  state: {
    // currentItem: {},
    // modalVisible: false,
    // modalType: 'create',
    // selectedRowKeys: [],
  },

  subscriptions: {
    setup ({ dispatch, history }) {
      history.listen(location => {
        if (location.pathname === '/getSpecificResult/') {
          dispatch({
            type: 'query',
            payload: location.query,
          })
        }
      })
    },
  },

  effects: {

    *query ( {payload}  , { call, put }) {
      const data = yield call(queryspecific, payload)
      if (data ) {
        let isString=typeof data.data

        if(isString=='string'){

          yield put({
            type: 'querySuccess',
            payload: {
              list: JSON.parse(data.data),

            },
          })
        }

      }
    },




  },

  reducers: {

    // showModal (state, { payload }) {
    //   return { ...state, ...payload, modalVisible: true }
    // },
    //
    // hideModal (state) {
    //   return { ...state, modalVisible: false }
    // },
  },
})
